import psycopg2
import sys

conn = None
try:
    conn = psycopg2.connect(
        host="172.16.137.39",
        port=5432, 
        database='a2513220218',
        user='a2513220218',  
        password='xawl-6043') 

    cur = conn.cursor()
    cur.execute('SELECT version()')

    version = cur.fetchone()[0]
    print(version)
    
except psycopg2.DatabaseError as e:
    print(f'Error {e}')
    sys.exit(1)
finally:
    if conn:
        conn.close()